<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="计划名称" prop="planName">
            <el-input v-model="queryParams.planName" placeholder="请输入计划名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="学年" prop="planXn">
            <el-input v-model="queryParams.planXn" placeholder="请输入学年" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <!-- <el-form-item label="知识与技能目标" prop="mbZj">
            <el-input v-model="queryParams.mbZj" placeholder="请输入知识与技能目标" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="过程与方法目标" prop="mbGf">
            <el-input v-model="queryParams.mbGf" placeholder="请输入过程与方法目标" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="情感态度价值目标" prop="mbQg">
            <el-input v-model="queryParams.mbQg" placeholder="请输入情感态度价值目标" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="主要知识点" prop="nrZsd">
            <el-input v-model="queryParams.nrZsd" placeholder="请输入主要知识点" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="教学重点和难点" prop="nrJxzd">
            <el-input v-model="queryParams.nrJxzd" placeholder="请输入教学重点和难点" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="教学内容安排" prop="nrJxap">
            <el-input v-model="queryParams.nrJxap" placeholder="请输入教学内容安排" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="教学方法" prop="clJxff">
            <el-input v-model="queryParams.clJxff" placeholder="请输入教学方法" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="学习活动设计" prop="clXxhd">
            <el-input v-model="queryParams.clXxhd" placeholder="请输入学习活动设计" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="课程互动环节" prop="clKchd">
            <el-input v-model="queryParams.clKchd" placeholder="请输入课程互动环节" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="课时学识" prop="sjXs">
            <el-input v-model="queryParams.sjXs" placeholder="请输入课时学识" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="各环节时间比例" prop="sjBl">
            <el-input v-model="queryParams.sjBl" placeholder="请输入各环节时间比例" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="作业安排" prop="pjZyap">
            <el-input v-model="queryParams.pjZyap" placeholder="请输入作业安排" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="考核方式" prop="pjKhfs">
            <el-input v-model="queryParams.pjKhfs" placeholder="请输入考核方式" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="评价标准" prop="pjPjbz">
            <el-input v-model="queryParams.pjPjbz" placeholder="请输入评价标准" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="课程特殊要求" prop="tsKcyq">
            <el-input v-model="queryParams.tsKcyq" placeholder="请输入课程特殊要求" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="教师特殊要求" prop="tsJsyq">
            <el-input v-model="queryParams.tsJsyq" placeholder="请输入教师特殊要求" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            <el-button type="primary" @click="handleAdd" v-hasPermi="['core:teachPlan:add']">新增</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
       <h2>实验教学计划列表</h2>
      </template>

      <el-table v-loading="loading" :data="teachPlanList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="计划编号" align="center" prop="id"  />
        <el-table-column label="计划名称" align="center" prop="planName" />
        <el-table-column label="学年" align="center" prop="planXn" />
        <!-- <el-table-column label="知识与技能目标" align="center" prop="mbZj" />
        <el-table-column label="过程与方法目标" align="center" prop="mbGf" />
        <el-table-column label="情感态度价值目标" align="center" prop="mbQg" />
        <el-table-column label="主要知识点" align="center" prop="nrZsd" />
        <el-table-column label="教学重点和难点" align="center" prop="nrJxzd" />
        <el-table-column label="教学内容安排" align="center" prop="nrJxap" />
        <el-table-column label="教学方法" align="center" prop="clJxff" />
        <el-table-column label="学习活动设计" align="center" prop="clXxhd" />
        <el-table-column label="课程互动环节" align="center" prop="clKchd" />
        <el-table-column label="课时学识" align="center" prop="sjXs" />
        <el-table-column label="各环节时间比例" align="center" prop="sjBl" />
        <el-table-column label="作业安排" align="center" prop="pjZyap" />
        <el-table-column label="考核方式" align="center" prop="pjKhfs" />
        <el-table-column label="评价标准" align="center" prop="pjPjbz" />
        <el-table-column label="课程特殊要求" align="center" prop="tsKcyq" />
        <el-table-column label="教师特殊要求" align="center" prop="tsJsyq" /> -->
        <el-table-column label="上传人" align="center" prop="createBy" /> 
        <el-table-column label="上传时间" align="center" prop="createTime" /> 
        <el-table-column label="状态" align="center" prop="status" >
          <template #default="scope">
            <div   v-if="scope.row.delFlag == '0'">有效</div>
            <div   v-else>废止</div>
          </template>
           </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
          <template #default="scope">
              <el-button type="text" size="small"  @click="handleUpdate(scope.row,0)" v-hasPermi="['core:teachPlan:edit']">编辑</el-button>
              <el-button type="text" size="small"  @click="handleUpdate(scope.row,1)" v-hasPermi="['core:teachPlan:edit']">查看</el-button>
              <el-button type="text" size="small"  @click="handleStatus(scope.row,)" v-hasPermi="['core:teachPlan:edit']" v-if="scope.row.delFlag == '0'">废止</el-button>
              <el-button type="text" size="small"  @click="handleStatus(scope.row,)" v-hasPermi="['core:teachPlan:edit']" v-else>生效</el-button>
              <el-button type="text" size="small" @click="handleDelete(scope.row)" v-hasPermi="['core:teachPlan:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
      />
    </el-card>
   
   
  </div>
</template>

<script setup name="TeachPlan" lang="ts">
import { listTeachPlan, getTeachPlan, delTeachPlan, addTeachPlan, updateTeachPlan } from '@/api/core/teachPlan';
import { TeachPlanVO, TeachPlanQuery, TeachPlanForm } from '@/api/core/teachPlan/types';
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const teachPlanList = ref<TeachPlanVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const teachPlanFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: TeachPlanForm = {
  planName: undefined,
  planXn: undefined,
  mbZj: undefined,
  mbGf: undefined,
  mbQg: undefined,
  nrZsd: undefined,
  nrJxzd: undefined,
  nrJxap: undefined,
  clJxff: undefined,
  clXxhd: undefined,
  clKchd: undefined,
  sjXs: undefined,
  sjBl: undefined,
  pjZyap: undefined,
  pjKhfs: undefined,
  pjPjbz: undefined,
  tsKcyq: undefined,
  tsJsyq: undefined,
  delFlag:undefined,
}
const data = reactive<PageData<TeachPlanForm, TeachPlanQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    planName: undefined,
    planXn: undefined,
    mbZj: undefined,
    mbGf: undefined,
    mbQg: undefined,
    nrZsd: undefined,
    nrJxzd: undefined,
    nrJxap: undefined,
    clJxff: undefined,
    clXxhd: undefined,
    clKchd: undefined,
    sjXs: undefined,
    sjBl: undefined,
    pjZyap: undefined,
    pjKhfs: undefined,
    pjPjbz: undefined,
    tsKcyq: undefined,
    tsJsyq: undefined,
    delFlag:undefined,
    params: {
    }
  },
  rules: {
    planName: [
      { required: true, message: "计划名称不能为空", trigger: "blur" }
    ],
    planXn: [
      { required: true, message: "学年不能为空", trigger: "blur" }
    ],
    mbZj: [
      { required: true, message: "知识与技能目标不能为空", trigger: "blur" }
    ],
    mbGf: [
      { required: true, message: "过程与方法目标不能为空", trigger: "blur" }
    ],
    mbQg: [
      { required: true, message: "情感态度价值目标不能为空", trigger: "blur" }
    ],
    nrZsd: [
      { required: true, message: "主要知识点不能为空", trigger: "blur" }
    ],
    nrJxzd: [
      { required: true, message: "教学重点和难点不能为空", trigger: "blur" }
    ],
    nrJxap: [
      { required: true, message: "教学内容安排不能为空", trigger: "blur" }
    ],
    clJxff: [
      { required: true, message: "教学方法不能为空", trigger: "blur" }
    ],
    clXxhd: [
      { required: true, message: "学习活动设计不能为空", trigger: "blur" }
    ],
    clKchd: [
      { required: true, message: "课程互动环节不能为空", trigger: "blur" }
    ],
    sjXs: [
      { required: true, message: "课时学识不能为空", trigger: "blur" }
    ],
    sjBl: [
      { required: true, message: "各环节时间比例不能为空", trigger: "blur" }
    ],
    pjZyap: [
      { required: true, message: "作业安排不能为空", trigger: "blur" }
    ],
    pjKhfs: [
      { required: true, message: "考核方式不能为空", trigger: "blur" }
    ],
    pjPjbz: [
      { required: true, message: "评价标准不能为空", trigger: "blur" }
    ],
    tsKcyq: [
      { required: true, message: "课程特殊要求不能为空", trigger: "blur" }
    ],
    tsJsyq: [
      { required: true, message: "教师特殊要求不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询实验教学计划列表 */
const getList = async () => {
  loading.value = true;
  const res = await listTeachPlan(queryParams.value);
  teachPlanList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}

/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  teachPlanFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: TeachPlanVO[]) => {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
const handleAdd = () => {
  // reset();
  // dialog.visible = true;
  // dialog.title = "添加实验教学计划";
  router.push({ path: '/experiment/teachPlan/panel',query: { type: 0}});
}

/** 修改按钮操作 */
const handleUpdate = async (row?: TeachPlanVO,type?:number) => {
  const id= row?.id || ids.value[0]
  // router.push('/base/student/add'+id);
 
    router.push({ path: '/experiment/teachPlan/panel',query: { id: id,type: type }});
 
  
}

/** 提交按钮 */
const submitForm = () => {
  teachPlanFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateTeachPlan(form.value).finally(() =>  buttonLoading.value = false);
      } else {
        await addTeachPlan(form.value).finally(() =>  buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("修改成功");
      dialog.visible = false;
      await getList();
    }
  });
}
/** 状态按钮操作 */
const handleStatus = async (row?: TeachPlanVO) => {
  const _ids = row?.id || ids.value;
  if (row?.delFlag  == '0') {
    form.value.delFlag ='1'
    await proxy?.$modal.confirm('是否确认废止实验教学计划编号为"' + _ids + '"的数据项？').finally(() => loading.value = false);
    await updateTeachPlan(form.value)
  }else{
    form.value.delFlag = '0'
    await proxy?.$modal.confirm('是否确认启用实验教学计划编号为"' + _ids + '"的数据项？').finally(() => loading.value = false);
    await updateTeachPlan(form.value)
  }
  proxy?.$modal.msgSuccess("操作成功");
  await getList();
}
/** 删除按钮操作 */

const handleDelete = async (row?: TeachPlanVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除实验教学计划编号为"' + _ids + '"的数据项？').finally(() => loading.value = false);
  await delTeachPlan(_ids);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('core/teachPlan/export', {
    ...queryParams.value
  }, `teachPlan_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList();
});
</script>
